#include "mainwindow.h"
#include "./ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setCentralWidget(ui->customizedOpenGLWidget);
    shapeActionsList.append(ui->drawRectAction);
    shapeActionsList.append(ui->drawTriangleAction);

    connect(ui->drawRectAction, &QAction::triggered, [=](bool state){
        ui->customizedOpenGLWidget->startDrawRect(state);
        updateShapeActionToolBar(ui->drawRectAction);
    });

    connect(ui->drawTriangleAction, &QAction::triggered, [=](bool state){
        ui->customizedOpenGLWidget->startDrawTriangle(state);
        updateShapeActionToolBar(ui->drawTriangleAction);
    });

    connect(ui->polygonModeAction, &QAction::triggered, ui->customizedOpenGLWidget, &CustomizedOpenGLWidget::setPolygonMode);
    connect(ui->clearCanvasAction, &QAction::triggered, ui->customizedOpenGLWidget, &CustomizedOpenGLWidget::clearCanvas);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::updateShapeActionToolBar(QAction *shapeAction)
{
    for (QAction* action: shapeActionsList){
        if (action == shapeAction) {
            continue;
        }
        else {
            action->setChecked(false);
        }
    }
}
